
package cn.edu.scau.cmi.hombio.domain;

import java.io.Serializable;

import java.lang.StringBuilder;

import java.util.Calendar;
import java.util.Set;

import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;

import org.codehaus.jackson.annotate.JsonIgnore;

import javax.xml.bind.annotation.*;

import javax.persistence.*;

/**
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllFeeds", query = "select myFeed from Feed myFeed"),
		@NamedQuery(name = "findFeedById", query = "select myFeed from Feed myFeed where myFeed.id = ?1"),
		@NamedQuery(name = "findFeedByMemo", query = "select myFeed from Feed myFeed where myFeed.memo = ?1"),
		@NamedQuery(name = "findFeedByMemoContaining", query = "select myFeed from Feed myFeed where myFeed.memo like ?1"),
		@NamedQuery(name = "findFeedByPrimaryKey", query = "select myFeed from Feed myFeed where myFeed.id = ?1"),
		@NamedQuery(name = "findFeedByTime", query = "select myFeed from Feed myFeed where myFeed.time = ?1") })

@Table(catalog = "pig", name = "feed")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "pigRs/cn/edu/scau/cmi/hombio/domain", name = "Feed")

public class Feed implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */

	@Column(name = "Id", nullable = false)
	@Basic(fetch = FetchType.EAGER)

	@Id @GeneratedValue
	@XmlElement
	Integer id;
	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "Time", nullable = false)
	@Basic(fetch = FetchType.EAGER)

	@XmlElement
	Calendar time;
	/**
	 */

	@Column(name = "Memo")
	@Basic(fetch = FetchType.EAGER)

	@XmlElement
	String memo;

	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "EmployeeId", referencedColumnName = "Id", nullable = false) })
	@XmlTransient
	Employee employee;
	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "TaskId", referencedColumnName = "Id", nullable = false) })
	@XmlTransient
	Task task;
	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "PigstyId", referencedColumnName = "Id", nullable = false) })
	@XmlTransient
	Pigsty pigsty;

	/**
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 */
	public Integer getId() {
		return this.id;
	}

	/**
	 */
	public void setTime(Calendar time) {
		this.time = time;
	}

	/**
	 */
	public Calendar getTime() {
		return this.time;
	}

	/**
	 */
	public void setMemo(String memo) {
		this.memo = memo;
	}

	/**
	 */
	public String getMemo() {
		return this.memo;
	}

	/**
	 */
	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	/**
	 */
	@JsonIgnore
	public Employee getEmployee() {
		return employee;
	}

	/**
	 */
	public void setTask(Task task) {
		this.task = task;
	}

	/**
	 */
	@JsonIgnore
	public Task getTask() {
		return task;
	}

	/**
	 */
	public void setPigsty(Pigsty pigsty) {
		this.pigsty = pigsty;
	}

	/**
	 */
	@JsonIgnore
	public Pigsty getPigsty() {
		return pigsty;
	}

	/**
	 */
	public Feed() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(Feed that) {
		setId(that.getId());
		setTime(that.getTime());
		setMemo(that.getMemo());
		setEmployee(that.getEmployee());
		setTask(that.getTask());
		setPigsty(that.getPigsty());
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");
		buffer.append("time=[").append(time).append("] ");
		buffer.append("memo=[").append(memo).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof Feed))
			return false;
		Feed equalCheck = (Feed) obj;
		if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
			return false;
		if (id != null && !id.equals(equalCheck.id))
			return false;
		return true;
	}
}
